package edu.zut.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

//自定义转换器  实现Converter
@Configuration
public class MyConverter implements Converter<String, LocalDate> {

    //定义转换逻辑
    @Override
    public LocalDate convert(String source) {
        if (source == null || source.length() == 0){
            return LocalDate.now();
        }
        LocalDate localDate = LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        return localDate;
    }
}
